package com.example.myvideo.View.impl;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.myvideo.database.DBHelper;
import com.example.myvideo.model.AuthModel;

public class AuthModelImpl implements AuthModel {
    private DBHelper dbHelper;

    public AuthModelImpl(Context context, DBHelper dbHelper) {
        this.dbHelper = dbHelper;
    }

    @Override
    public boolean checkUserExists(String username) {
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        Cursor cursor = db.query(DBHelper.getUsersTable(), new String[]{DBHelper.getIdColumn()}, DBHelper.getUsernameColumn() + "=?", new String[]{username}, null, null, null);
        boolean exists = cursor.getCount() > 0;
        cursor.close();
        return exists;
    }

    @Override
    public long addUser(String username, String password, String avatarPath) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(DBHelper.getUsernameColumn(), username);
        values.put(DBHelper.getPasswordColumn(), password);
        values.put(DBHelper.getAvatarPathColumn(), avatarPath);
        return db.insert(DBHelper.getUsersTable(), null, values);
    }
    @Override
    public boolean authenticateUser(String username, String password) {
        // 实现用户认证的逻辑
        return false;
    }

    @Override
    public void saveAvatar(String path) {
        // 实现保存用户头像的逻辑
    }
}